package com.itheima.admin.controller;

import com.itheima.admin.dto.AdSensitivePageRequestDto;
import com.itheima.admin.pojo.AdSensitive;
import com.itheima.admin.service.AdSensitiveService;
import com.itheima.common.exception.LeadNewsException;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import com.itheima.core.controller.AbstractCoreController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sensitive")
@Api(tags = "敏感词管理")
@Slf4j
public class AdSensitiveController extends AbstractCoreController<AdSensitive> {


    @Autowired
    private AdSensitiveService adSensitiveService;

    @Autowired
    public AdSensitiveController(AdSensitiveService adSensitiveService){
        super(adSensitiveService);
    }

    /**
     * 敏感词分页查询
     *
     * @param dto
     * @return
     */

    @ApiOperation("敏感词分页搜索")
    @PostMapping("/list")
    public PageResultVo list(@RequestBody AdSensitivePageRequestDto dto) {
        PageResultVo pageResultVo = adSensitiveService.pageList(dto);
        return pageResultVo;
    }


    /**
     * 新增敏感词
     *
     * @param adSensitive
     * @return
     */
    @ApiOperation("新增敏感词")
    @PostMapping("/save")
    @Override
    public ResultVo insert(@RequestBody AdSensitive adSensitive) {
        if (null ==adSensitive){
            throw new LeadNewsException("对象为空");
        }
        Boolean aBoolean = adSensitiveService.add(adSensitive);
        if (aBoolean) {
            return ResultVo.ok("success");
        }
        return ResultVo.error();
    }





}
